`:top
A `!Windows Script File`! (`!WSF`!) is a file type used by the `F33f`_`[Microsoft`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Microsoft]`_`f `F33f`_`[Windows Script Host`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Windows_Script_Host]`_`f. It allows mixing the `F33f`_`[scripting languages`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Scripting_language]`_`f `F33f`_`[JScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JScript]`_`f and `F33f`_`[VBScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=VBScript]`_`f within a single file, or other scripting languages such as `F33f`_`[Perl`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Perl]`_`f, `F33f`_`[Object REXX`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object_REXX]`_`f, `F33f`_`[Python`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Python_(programming_language)]`_`f, or `F33f`_`[Kixtart`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Kixtart]`_`f if installed by the user. These types of scripts may also be used to link many other external scripts together using a `B100`F9d9src`f`b parameter on the `B100`F9d9<script>`f`b tag in a manner similar to `F33f`_`[HTML`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=HTML]`_`f. Windows Script Files have the extension `B100`F9d9".WSF"`f`b. A WSF makes reference to each script module in a very basic `F33f`_`[XML`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XML]`_`f hierarchy as shown below, adhering to those standards outside the `B100`F9d9<script>`f`b tags. Literal use of "`B100`F9d9</script>`f`b" or "`B100`F9d9<script>`f`b" inside your `B100`F9d9<script>`f`b tags and similar challenges can be handled by the use of `F33f`_`[CDATA`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=CDATA]`_`f, as shown within the examples.
>>Contents
• `F0af`_`[Error isolation`#error-isolation]`_`f
• `F0af`_`[Mixed language support`#mixed-language-support]`_`f
• `F0af`_`[Exposing constants`#exposing-constants]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[External links`#external-links]`_`f
-─
>>Error isolation
A WSF may be useful for isolating errors. Its modular nature prevents one script reference from interfering with another. Here is a WSF example with one module that produces an error and one that does not:
`B100`F9d9<?xml version="1.0" ?>`f`b
`B100`F9d9 <job id="Partially works">`f`b
`B100`F9d9 <!-- This will not work -->`f`b
`B100`F9d9 <script language="VBScript">`f`b
`B100`F9d9' <![CDATA[`f`b
`B100`F9d9 WScript.echo 4/0 ' Oh, boy! You cannot divide by zero...`f`b
`B100`F9d9' ]]>`f`b
`B100`F9d9 </script>`f`b
`B100`F9d9 <!-- This will work... definitely... -->`f`b
`B100`F9d9 <script language="VBScript">`f`b
`B100`F9d9' <![CDATA[`f`b
`B100`F9d9 WScript.echo "Hello, Scripters!" & vbNewline & _`f`b
`B100`F9d9 "Fantastic! It worked!"`f`b
`B100`F9d9' ]]>`f`b
`B100`F9d9 </script>`f`b
`B100`F9d9 </job>`f`b
The first script module will produce a "divide by zero" error. Typically this would cause the script to end in the `F33f`_`[Windows Script Host`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Windows_Script_Host]`_`f but this modular method allows the script to continue and execute the second script module.
>>Mixed language support
A Windows Script File supports multiple languages, as described on the `F33f`_`[Windows Script Host`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Windows_Script_Host]`_`f reference. One of the features of this file format is that you may use more than one at once. This means you can have one scripting language use code from another scripting language. The most memorable example for long-time `F33f`_`[VBScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=VBScript]`_`f users is the use of Microsoft `F33f`_`[JScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JScript]`_`f to service a sort request for `F33f`_`[VBScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=VBScript]`_`f since it does not have a built-in sort function for an array of values. `F33f`_`[VBScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=VBScript]`_`f users may write their own sort method or borrow one from an existing object like an ADO (`F33f`_`[ActiveX Data Objects`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ActiveX_Data_Objects]`_`f) `F33f`_`[Recordset`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Recordset]`_`f or a .NET (`F33f`_`[.NET Framework`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=.NET_Framework]`_`f) `F33f`_`[ArrayList`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ArrayList]`_`f, but the fastest way to sort an array is to use the method built into `F33f`_`[JScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JScript]`_`f. Here is a basic example of how that works:
`B100`F9d9<?xml version="1.0" ?>`f`b
`B100`F9d9<!-- Mixing JScript and VBScript -->`f`b
`B100`F9d9 <job id="SORT-VBScriptWithJScript">`f`b
`B100`F9d9 <script language="JScript">`f`b
`B100`F9d9 function SortVBArray(arrVBArray) {return arrVBArray.toArray().sort();}`f`b
`B100`F9d9 </script>`f`b
`B100`F9d9 <script language="VBScript">`f`b
`B100`F9d9' <![CDATA[`f`b
`B100`F9d9 '** Fastest sort: call the Jscript sort from VBScript`f`b
`B100`F9d9 myData = "a,b,c,1,2,3,X,Y,Z,p,d,q"`f`b
`B100`F9d9 wscript.echo "Original List of values: " & vbTab & myData`f`b
`B100`F9d9 starttime = timer()`f`b
`B100`F9d9 sortedArray = SortVBArray(split(myData,","))`f`b
`B100`F9d9 endtime=timer()`f`b
`B100`F9d9 jscriptTime = round(endtime-starttime,2)`f`b
`B100`F9d9 wscript.echo "JScript sorted in " & jscriptTime & " seconds: " & vbTab & sortedArray`f`b
`B100`F9d9' ]]>`f`b
`B100`F9d9 </script>`f`b
`B100`F9d9 </job>`f`b
The output looks like this, sorted by `F33f`_`[ASCII`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ASCII]`_`f code sequence:
`B100`F9d9Original List of values: a,b,c,1,2,3,X,Y,Z,p,d,q`f`b
`B100`F9d9JScript sorted in 0 seconds: 1,2,3,X,Y,Z,a,b,c,d,p,q`f`b
>>Exposing constants
Another very useful feature of a WSF is that the XML wrapper can be bound to an object reference or control so you can use that object's constants instead of having to declare them. In regular `F33f`_`[VBScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=VBScript]`_`f and `F33f`_`[JScript`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JScript]`_`f files, you would be forced to declare a constant's value (outside those that are internal to the `F33f`_`[Windows Script Host`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Windows_Script_Host]`_`f) in order to use the constant. An example of this is shown below:
`B100`F9d9const adLockBatchOptimistic = 4`f`b
`B100`F9d9MsgBox "The value of ""adLockBatchOptimistic"" is " & _`f`b
`B100`F9d9 adLockBatchOptimistic & ".", vbInformation,"adLockBatchOptimistic"`f`b
If your object documentation only refers to the constant's name and not the constant's value, you would have no way of knowing the value without the help of an `F33f`_`[Integrated development environment`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Integrated_development_environment]`_`f to tell you what they equate to. By using the WSF reference declaration, you can use the constants without declaring their values. The example below enumerates the values of several common constants in the ADO (`F33f`_`[ActiveX Data Objects`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ActiveX_Data_Objects]`_`f) `F33f`_`[Recordset`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Recordset]`_`f.
`B100`F9d9<?xml version="1.0" ?>`f`b
`B100`F9d9<!-- WSF Example with Object Reference`f`b
`B100`F9d9Notes for this very formal example:`f`b
`B100`F9d9 CDATA is used to help the XML parser ignore`f`b
`B100`F9d9 special characters in the content of the script.`f`b
`B100`F9d9 The CDATA open and close must be masked`f`b
`B100`F9d9 from VBScript by making them comments.`f`b
`B100`F9d9-->`f`b
`B100`F9d9<package>`f`b
`B100`F9d9 <job id="EnumerateConstantsADO">`f`b
`B100`F9d9 <reference object="ADODB.Recordset" />`f`b
`B100`F9d9 <script language="VBScript">`f`b
`B100`F9d9' <![CDATA[`f`b
`B100`F9d9 dim title, str, i`f`b
`B100`F9d9 ctecArray = Array("adOpenUnspecified","adOpenForwardOnly", _`f`b
`B100`F9d9 "adOpenKeyset","adOpenDynamic","adOpenStatic")`f`b
`B100`F9d9 title = "ADO Recordset Values for Constants"`f`b
`B100`F9d9 str = title & vbNewLine & vbNewLine`f`b
`B100`F9d9 str = str & "*CursorTypeEnum Constants*" & vbNewLine`f`b
`B100`F9d9 For i = 0 to ubound(ctecArray)`f`b
`B100`F9d9 str = str & Eval(ctecArray(i)) & vbTab & ctecArray(i) & vbNewLine`f`b
`B100`F9d9 Next`f`b
`B100`F9d9 str = str & vbNewLine`f`b
`B100`F9d9 str = str & "*LockTypeEnum Constants*" & vbNewLine`f`b
`B100`F9d9 ltecArray = Array("adLockUnspecified","adLockReadOnly", _`f`b
`B100`F9d9 "adLockPessimistic","adLockOptimistic", _`f`b
`B100`F9d9 "adLockBatchOptimistic")`f`b
`B100`F9d9 For i = 0 to ubound(ltecArray)`f`b
`B100`F9d9 str = str & Eval(ltecArray(i)) & vbTab & ltecArray(i) & vbNewLine`f`b
`B100`F9d9 Next`f`b
`B100`F9d9 MsgBox str, vbInformation, Title`f`b
`B100`F9d9' ]]>`f`b
`B100`F9d9 </script>`f`b
`B100`F9d9 </job>`f`b
`B100`F9d9</package>`f`b
Running the above script from a file with a `B100`F9d9".WSF"`f`b extension, such as one named `B100`F9d9"EnumerateConstantsADO.wsf"`f`b, will produce the result shown below:
`B100`F9d9ADO Recordset Values for Constants`f`b
`B100`F9d9`f`b
`B100`F9d9*CursorTypeEnum Constants*`f`b
`B100`F9d9-1 adOpenUnspecified`f`b
`B100`F9d90 adOpenForwardOnly`f`b
`B100`F9d91 adOpenKeyset`f`b
`B100`F9d92 adOpenDynamic`f`b
`B100`F9d93 adOpenStatic`f`b
`B100`F9d9`f`b
`B100`F9d9*LockTypeEnum Constants*`f`b
`B100`F9d9-1 adLockUnspecified`f`b
`B100`F9d91 adLockReadOnly`f`b
`B100`F9d92 adLockPessimistic`f`b
`B100`F9d93 adLockOptimistic`f`b
`B100`F9d94 adLockBatchOptimistic`f`b
In addition, using the object reference to expose the constants makes writing the script more like writing in a standard programming language. In fact, the contents of the sample script, written in VBScript, will actually compile into a `F33f`_`[Visual Basic`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Visual_Basic]`_`f program and run the same way as long as that program uses the same reference to ADODB.
>>See also
• `F33f`_`[Active Scripting`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Active_Scripting]`_`f
• `F33f`_`[Shell script`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Shell_script]`_`f
• `F33f`_`[HTML Application`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=HTML_Application]`_`f
• `F33f`_`[PowerShell`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=PowerShell]`_`f
>>External links
• Using Windows Script Files - From `F33f`_`[The WayBack Machine's`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=The_Wayback_Machine]`_`f archive of a page from `F33f`_`[Microsoft's`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Microsoft]`_`f website
• Scripting Languages Available in the Script Center - From `F33f`_`[The WayBack Machine's`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=The_Wayback_Machine]`_`f archive of a page from `F33f`_`[Microsoft's`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Microsoft]`_`f website
`c`F0af`_`[↑ Back to top`#top]`_`f`a